/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tetris;

import java.awt.*;

/**
 *
 * @author CJ
 */
public class Square_Block extends Block{

    public Square_Block(int x, int y, int rate, char dir, int l, int w)
    {
        super(x, y, rate, dir, l, w);
        color = Color.orange;
    }

    public Square_Block()
    {
        super();
        color = Color.orange;
    }

    public void rotate()
    {}

    public void draw(Graphics g, Board b)
    {
        if(!stopped)
            shadowDraw(g, b);

        g.setColor(color);
        g.fillRect(x, y, 20, 20);
        g.setColor(Color.black);
        g.drawRect(x, y, 10, 10);
        g.drawRect(x + 10, y, 10, 10);
        g.drawRect(x + 10, y + 10, 10, 10);
        g.drawRect(x, y + 10, 10, 10);
    }

    public void makearea()
    {
        boundarea = new int[][]
        {{y/10 + 1, x/10},
         {y/10 + 1, x/10 + 1},
         {y/10 + 2, x/10},
         {y/10 + 2, x/10 + 1}};
    }

    public void setX(int x, Board b)
    {
        if(x < 0 || x + 20 > WIDTH)
            return;

        if(x > this.x)
        {
            //User wants to move to the right;
            if(!b.move(new Square_Block(this.x + 10, y - 10, (int)rate, dir, LENGTH, WIDTH)))
                return;
        }
        else
        {
            //User wants to move to the left
            if(!b.move(new Square_Block(this.x - 10, y - 10, (int)rate, dir, LENGTH, WIDTH)))
                return;
        }

        this.x = x;
        makearea();
    }

    public boolean canMoveY(Board b)
    {
        if(y + 20 >= LENGTH
                || !b.move(this))
        {
            b.put(this);
            return false;
        }
        return true;
    }

    public void shadowDraw(Graphics g, Board b)
    {
        Square_Block theBlock = new Square_Block(x, y, (int)rate, dir, LENGTH, WIDTH);

        while(b.move(theBlock) && theBlock.getY() + 20 < LENGTH)
        {
            theBlock.setY(theBlock.getY() + 10);
        }

        int y = theBlock.getY();

        g.setColor(Color.black);
        g.drawRect(x, y, 20, 20);

    }

}
